package com.spring;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import java.text.DateFormat;
import java.util.Date;

//开启定时任务
@EnableScheduling
@EnableAsync
@SpringBootApplication
public class StartApplication {

    public static void main(String[] args) {
        SpringApplication.run(StartApplication.class, args);
    }

    /**
     * 半小时体现一次 /30秒
     */
    @Scheduled(fixedRate = 30 * 1000)
    @Async
    // @Scheduled(cron = "0 0/30 9-22 * * ?")
    public void playSay() {
        System.out.println("线程" + Thread.currentThread().getName());
        System.out.println("发送微信体现女神多喝水" + DateFormat.getDateTimeInstance().format(new Date()));
    }

    /**
     * 四小时提醒一次 /一分钟
     */
    @Scheduled(fixedRate = 1 * 60 * 1000)
    @Async
    // @Scheduled(cron = "0 0 9-22/4 * * ?")
    public void playSay2() {
        System.out.println("线程" + Thread.currentThread().getName());
        System.out.println("发送微信体现女神该吃药了..." + DateFormat.getDateTimeInstance().format(new Date()));
    }
}
